const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'built.js',
        path: resolve(__dirname, 'build')
    },
    module: {
        rules: [
            {
                /*
                语法检查: eslint-loader eslint
                    注意: 只检查自己写的源代码，第三方的库是不用检查的
                    设置检查规则：（在 package.json中 eslintConfig 中设置）
                        "eslintConfig": {
                            "extends": "airbnb-base"
                        }
                        airbnb --> eslint-config-airbnb-base eslint-plugin-import eslint
                */ 
               test: /\.js$/,
               exclude: /node_modules/,
               loader: 'eslint-loader',
               options: {
                // 启动自动修复 eslint 的错误
                fix: true
               }

            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ],
    mode: 'development',
    devServer: {
        contentBase: resolve(__dirname, 'build'),
        compress: true,
        port: 3000,
        open: true
    }
}